package summerprojectFX.controller;

import java.io.File;
import summerprojectFX.model.Song;
import summerprojectFX.parser.*;
import summerprojectFX.utilities.NashvilleNumbers;
import summerprojectFX.utilities.Transposer;
import summerprojectFX.view.FullScreenView;
import summerprojectFX.view.MainView;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.control.MenuItem;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import summerprojectFX.view.HelpContent;

public class MenuController implements EventHandler<ActionEvent> {

	private Song song;
	private Stage primary;
	private MainView view;

	public MenuController(Stage primaryStage, MainView view) {
		primary = primaryStage;
		this.view = view;

	}

	@Override
	public void handle(ActionEvent event) {
		MenuItem m = (MenuItem) event.getSource();
		song = new Song();
		Song test = view.getSelectedSong();
		if (m.getText().equals("Open File")) {
			OpenFile of = new OpenFile(view, primary);

		} else if (m.getText().equals("Save As") && view.getSelectedSong().getLyrics() != null) {
			SaveAs sa = new SaveAs(view, primary);

		} else if (m.getText().equals("Close All")) {
			view.clearList();

		} else if (m.getText().equals("Close")) {
			view.clearSelected();

		}else if (m.getText().equals("Export As PDF") && view.getSelectedSong().getLyrics() != null) {
			ExportPDF pdf = new ExportPDF(view, primary);

		} 
		else if (m.getText().equals("Exit")) {
			System.exit(0);
		} else if (m.getText().equals("Number System") ) {
			Song song = view.getSelectedSong();
			if(song.getTitle() != null){
				String currentSong = song.getLyrics();

				NashvilleNumbers nn = new NashvilleNumbers(currentSong,
						view.getKey());
				String numbersSong = nn.convert();
				song.setLyrics(numbersSong);
				song.setNumeric(numbersSong);
			
			}
			view.goToNumber(song);
		} else if (m.getText().equals("Restore Original") && view.getSelectedSong().getLyrics() != null) {
			view.restore();
		} else if (m.getText().equals("Previous") && view.getSelectedSong().getLyrics() != null) {
			view.previous();
		} else if (m.getText().equals("Transpose") && view.getSelectedSong().getLyrics() != null) {
			Song song = view.getSelectedSong();
			String currentSong = song.getLyrics();
			Transposer tranny = new Transposer(currentSong,
					view.getKeyLetter(), view.getHalfSteps());
			String transposedSong = tranny.transpose();
			song.setLyrics(transposedSong);
			view.goToNumber(song);
		}else if(m.getText().equals("Full Screen") && view.getSelectedSong().getLyrics() != null){
				
				try {
					
					FullScreenView fs = new FullScreenView(view.getCurrentSongs(), view.getSelectedSong(), view);
					fs.start(new Stage());
				
				} catch (Exception e) {
					
					e.printStackTrace();
				}
			
			
		}else if(m.getText().equals("Help Contents")){
                    HelpContent hp = new HelpContent();
                    hp.start(new Stage());
                }
	}

}
